package com.atguigu.demo.day17springboot.config;

import com.atguigu.demo.day17springboot.service.AgeService;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@ConditionalOnClass(AgeService.class)
@EnableConfigurationProperties(AgeProperties.class)
public class AgeAutoConfiguration {
    private final AgeProperties ageProperties;

    public AgeAutoConfiguration(AgeProperties ageProperties) {
        this.ageProperties = ageProperties;
    }
    @Bean
    @ConditionalOnMissingBean
    public AgeService ageService(){
        return new AgeService(ageProperties.getBirthday());
    }
}
